package com.zyx.crawlerdemo.jsoup.jsoupconnect;

import com.zyx.crawlerdemo.utils.BufferUtils;
import org.jsoup.Connection.Method;
import org.jsoup.Connection.Response;
import org.jsoup.Jsoup;

import java.io.BufferedInputStream;
import java.io.IOException;

/**
 * @author Yaxi.Zhang
 * @since 2021/8/11 16:07
 * desc:
 */
public class JsoupConnectBodySize1 {
    public static void main(String[] args) throws IOException {
        String url = "https://www-us.apache.org/dist//httpd/httpd-2.4.37.tar.gz";
        // 超时时间设置长一些，下载大文件
        Response response = Jsoup.connect(url).timeout(10 * 60 * 1000)
                .maxBodySize(Integer.MAX_VALUE)
                .method(Method.GET).ignoreContentType(true).execute();
        // 如果响应成功，则执行下面的操作
        if (response.statusCode() == 200) {
            // 响应转化成输出流
            BufferedInputStream bufferedInputStream = response.bodyStream();
            // 保存图片
            BufferUtils.bufferToFile(bufferedInputStream, "image/httpd-2.4.37.tar.gz");
        }
    }
}
